package org.ahuanlien.crm.web.controller;

import org.ahuanlien.crm.domain.Permission;
import org.ahuanlien.crm.query.QueryObject;
import org.ahuanlien.crm.service.IPermissionService;
import org.ahuanlien.crm.util.JSONResult;
import org.ahuanlien.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("permission")
public class PermissionController {

	@Autowired
	private IPermissionService permissionService;

	@RequestMapping("view")
	public String view() {
		return "permission/view";
	}

	@RequestMapping("query")
	@ResponseBody
	public PageResult query(QueryObject qo) {
		PageResult result = permissionService.query(qo);
		return result;
	}

	@RequestMapping("selectAll")
	@ResponseBody
	public List<Permission> selectAll() {
		return permissionService.selectAll();
	}

	@RequestMapping("selectPermissionByRoleId")
	@ResponseBody
	public List<Permission> selectPermissionByRoleId(Long roleId) {
		return permissionService.selectPermissionByRoleId(roleId);
	}
	@RequestMapping("reload")
	@ResponseBody
	public JSONResult reload() {
		try {
			permissionService.reload();
		} catch (Exception e) {
			e.printStackTrace();
			return JSONResult.mark("操作失败");
		}
		return JSONResult.success("操作成功");
	}



}
